<script>
	/**
	 * tabBar页面路径列表 (用于链接跳转时判断)
	 * tabBarLinks为常量, 无需修改
	 */
	const tabBarLinks = ['pages/index/index', 'pages/market/index/index', 'pages/user/index']; // 站点配置文件

	import siteinfo from './siteinfo.js'; // 工具类
	import JSEncrypt from '@/node_modules/encryptlong/bin/jsencrypt.js' //RSA
	import util from './utils/util.js';
	import {
		isWeixin
	} from './utils/verify.js';
	import updataApp from "@/uni_modules/uni-upgrade-center-app/utils/check-update"
	// #ifdef H5
	var jweixin = require('jweixin-module');
	// #endif

	export default {
		/**
		 * 全局变量
		 */
		globalData: {
			user_id: null,
			PUBLIC_KEY: `MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8c4bwMErGs9id9fPwWVD3b/Ol
			miss0j6OfwKgGn3ed/Y9vsIQJNsnbvoCRCXlP+YTlFEU1gZtr6kAVDYP7Mi+v5Vb
			b3xWfvKQ5LmFTFn0AC1QZQpdmbv05EEOefQOylw9rImG7d7B1r1FK3LKD/lz56ar
			M9pvKBkzF6jc+ZfZmwIDAQAB`,
			PRIVATE_KEY: `MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBALxzhvAwSsaz2J31
				8/BZUPdv86WaKyzSPo5/AqAafd539j2+whAk2ydu+gJEJeU/5hOUURTWBm2vqQBU
				Ng/syL6/lVtvfFZ+8pDkuYVMWfQALVBlCl2Zu/TkQQ559A7KXD2siYbt3sHWvUUr
				csoP+XPnpqsz2m8oGTMXqNz5l9mbAgMBAAECgYEAlmB5pOBkSvroN+Qzq+8ZtNkY
				y2SiXznFwV+IcMmy9vsy+0JlCQzf9C+SQIyw0KaUqbsImF/Q8WXireiE22BPLshs
				ssImWyuuHRzx3eg8HHbdIFclAC7fwRgZXjMEq7TeXEAh8WRNN4zuU0nwp08rV2jb
				6Bc2VYq6P4boRX4d0MECQQDijmt6BEZe/wkYx+OEWQ4HJgB1uVz700bYTgLwq1WG
				FnMk1EkAyd4e032Uh+BhY1xCgyBuPnZ99pYP0aOzLzF1AkEA1PFX+lvXLHoMB93D
				VSHjfbNafNIVKGKNHMbhBjwotp1Z6JBOEb5m0j2BmzTEAmEdEWeZt2a6Mk0rzvqa
				t5vszwJBAOEsblQSxaKLVw5DNbWIEbI3KgPX3TwJjINWXgO4NsOTspOrTnezK8p1
				p34l4nTJHZyZ2XTZLkoZ+KH2Wf6w7DUCQQDRG9NeWnPaDFvmGaLo5eeFF+xjKNZ4
				GxchzDdLrSX59llFJPhVOlm0WYv9wvo8r+sgnVD5JhrwrJG5pqTqa2dHAkAvQeqe
				SmZ32LxufwBoJ+P9WIpJjqg9Pup032qHznYvYUlbe1RyjQOfRtlBzWs6yzV8yL35
				Mz1Rfqi0xrFQJASf`,
			// api地址
			api_root: siteinfo.siteroot + 'index.php?s=/api/',
			curVersion : 3,
		},
		/**
		 * 生命周期函数--监听小程序初始化
		 */
		onLaunch(e) {
			let _this = this; // 小程序主动更新
			// #ifdef MP-WEIXIN 
			_this.updateManager(); // 小程序启动场景
			// #endif
			// #ifdef APP-PLUS
			    updataApp()
			// 更新app
			// _this.checkForUpdate();
			// uni.hideTabBar() // app隐藏底部tabBar
			
			// plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
			// 	let type = uni.getSystemInfoSync().platform
			// 	if( type == 'android'){
			// 		type = 1
			// 	}else{
			// 		type = 2
			// 	}
			// 	console.log(type)
			// 	console.log(widgetInfo.versionCode)
			// 	let param = {
			// 		version_code: parseInt(widgetInfo.versionCode),
			// 		type: type
			// 	}
			// 	console.log(param)
			//     _this._post_form('user/isUpdateVersion',param,(result) => {
			//             var data = result.data;
			// 			console.log(result)
			//             if (data.isUp && data.url) {
			// 				uni.showModal({
			// 					title: '有新版本更新'
			// 				})
			//                 uni.downloadFile({  
			//                     url: data.url,  
			//                     success: (downloadResult) => {
			// 						console.log(downloadResult)
			//                         if (downloadResult.statusCode === 200) {  
			//                             plus.runtime.install(downloadResult.tempFilePath, {  
			//                                 force: false  
			//                             }, function() {
											
			//                                 console.log('install success...');  
			//                                 plus.runtime.restart();  
			//                             }, function(e) {
			// 								uni.showModal({
			// 									title: '更新失败'
			// 								})
			//                                 console.error('install fail...');  
			//                             });  
			//                         }  
			//                     }  
			//                 });  
			//             }  
			//     });  
			// });  
			// #endif
			_this.onStartupScene(e.query);
			_this.weixinAuthorize(e.query);
		},
		/**
		 * 当小程序启动，或从后台进入前台显示，会触发 onShow
		 */
		onShow(options) {
			// 获取小程序基础信息
			// this.getWxappBase();
		},
		methods: {
			// 加密
			unCrypted(token){
				const PUBLIC_KEY =  `MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8c4bwMErGs9id9fPwWVD3b/Ol
				miss0j6OfwKgGn3ed/Y9vsIQJNsnbvoCRCXlP+YTlFEU1gZtr6kAVDYP7Mi+v5Vb
				b3xWfvKQ5LmFTFn0AC1QZQpdmbv05EEOefQOylw9rImG7d7B1r1FK3LKD/lz56ar
				M9pvKBkzF6jc+ZfZmwIDAQAB`
				// 使用设置公私钥
				const enc = new JSEncrypt();
				enc.setPublicKey(PUBLIC_KEY);
				// enc.setPublicKey(PRIVATE_KEY);
				// token = JSON.stringify(token);
				let encrypted = enc.encryptLong(token);
				// console.log("加密后数据:%o", encrypted);
				return encrypted
			},
			// 解密
			enCrypted(token){
				// 使用设置公私钥
				const enc = new JSEncrypt();
				// enc.setPublicKey(PUBLIC_KEY);
				enc.setPublicKey(`MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBALxzhvAwSsaz2J31
				8/BZUPdv86WaKyzSPo5/AqAafd539j2+whAk2ydu+gJEJeU/5hOUURTWBm2vqQBU
				Ng/syL6/lVtvfFZ+8pDkuYVMWfQALVBlCl2Zu/TkQQ559A7KXD2siYbt3sHWvUUr
				csoP+XPnpqsz2m8oGTMXqNz5l9mbAgMBAAECgYEAlmB5pOBkSvroN+Qzq+8ZtNkY
				y2SiXznFwV+IcMmy9vsy+0JlCQzf9C+SQIyw0KaUqbsImF/Q8WXireiE22BPLshs
				ssImWyuuHRzx3eg8HHbdIFclAC7fwRgZXjMEq7TeXEAh8WRNN4zuU0nwp08rV2jb
				6Bc2VYq6P4boRX4d0MECQQDijmt6BEZe/wkYx+OEWQ4HJgB1uVz700bYTgLwq1WG
				FnMk1EkAyd4e032Uh+BhY1xCgyBuPnZ99pYP0aOzLzF1AkEA1PFX+lvXLHoMB93D
				VSHjfbNafNIVKGKNHMbhBjwotp1Z6JBOEb5m0j2BmzTEAmEdEWeZt2a6Mk0rzvqa
				t5vszwJBAOEsblQSxaKLVw5DNbWIEbI3KgPX3TwJjINWXgO4NsOTspOrTnezK8p1
				p34l4nTJHZyZ2XTZLkoZ+KH2Wf6w7DUCQQDRG9NeWnPaDFvmGaLo5eeFF+xjKNZ4
				GxchzDdLrSX59llFJPhVOlm0WYv9wvo8r+sgnVD5JhrwrJG5pqTqa2dHAkAvQeqe
				SmZ32LxufwBoJ+P9WIpJjqg9Pup032qHznYvYUlbe1RyjQOfRtlBzWs6yzV8yL35
				Mz1Rfqi0xrFQJASf`);
				
				//使用私钥解密
				let uncrypted = enc.decryptLong(token);
				console.log("解密后数据:%o", uncrypted)
				return uncrypted
			},
			/**
			 * 小程序启动场景
			 */
			onStartupScene(query) {
				// 获取场景值
				let scene = this.getSceneData(query); // 记录推荐人id

				let refereeId = query.referee_id ? query.referee_id : scene.uid;

				if (refereeId > 0) {
					this.saveRefereeId(refereeId);
				}
			},

			/**
			 * 微信静默授权
			 * @param {Object} query 参数
			 */
			weixinAuthorize(query) {

				// #ifdef H5
				if (isWeixin()) {
					let redirect_uri = location.href.split('#')[0];
					if (redirect_uri.indexOf("login/register") > -1 || redirect_uri.indexOf("login/login") > -1) {
						window.location.href = location.origin + '/h5/pages/index/index' + location.search;
						return;
					}

					this.checkIsLogin(isLogin => {

						// 未登录状态
						if (!isLogin) {
							let openid = uni.getStorageSync('openid');

							// openid不存在，通过code登陆
							if ((!openid || openid == undefined)) {

								// code不存在，获取code
								if (!query.code) {

									// 微信静默授权登录
									let authURL =
										`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${siteinfo.gzh.APPID}&redirect_uri=${encodeURIComponent(redirect_uri)}&response_type=code&scope=snsapi_base&state=1&connect_redirect=1#wechat_redirect`;
									window.location.href = authURL;

								} else {
									this.wechatH5Login(null, query.code, query.invite_code);
								}

							} else {
								this.wechatH5Login(openid, null, query.invite_code);
							}

						}
					})
				}
				// #endif
			},

			/**
			 * 获取商城ID
			 */
			getWxappId() {
				return siteinfo.uniacid;
			},

			/**
			 * 记录推荐人id
			 */
			saveRefereeId(refereeId) {
				if (!uni.getStorageSync('referee_id')) {
					uni.setStorageSync('referee_id', refereeId);
				}
			},

			/**
			 * 获取场景值(scene:k:v,k:v)
			 */
			getSceneData(query) {
				return query.scene ? util.scene_decode(query.scene) : {};
			},

			/**
			 * 获取场景值(scene:k=v&k=v)
			 */
			aj_getSceneData(query) {
				return query.scene ? util.aj_scene_decode(query.scene) : {};
			},

			navigateToLogin() {
				// 保存当前页面
				let pages = getCurrentPages();
				if (pages.length) {
					let currentPage = pages[pages.length - 1];
					let route = currentPage.route;
					if ('pages/login/login' != route) {
						uni.setStorageSync('currentPage', route);
					}
				} // 跳转授权页面

				uni.navigateTo({
					url: '/pages/login/login'
				});
			},

			/**
			 * 执行用户登录
			 */
			doLogin() {
				// #ifdef H5
				if (isWeixin()) {
					this.wechatH5Login(uni.getStorageSync('openid'), null);
				} else {
					this.navigateToLogin();
				}
				// #endif

				// #ifndef H5
				this.navigateToLogin();
				// #endif

				// this.navigateToLogin();
			},

			/**
			 * 当前用户id
			 */
			getUserId() {
				return uni.getStorageSync('user_id');
			},

			/**
			 * 显示成功提示框
			 */
			showSuccess(msg, callback) {
				uni.showToast({
					title: msg,
					icon: 'success',
					mask: true,
					duration: 1500,

					success() {
						if (callback) {
							setTimeout(function() {
								callback();
							}, 1500);
						}
					}
				});
			},

			/**
			 * 显示成功提示框
			 */
			showSuccessWithDuration(duration, msg, callback) {
				uni.showToast({
					title: msg,
					icon: 'success',
					mask: true,
					duration: duration,

					success() {
						if (callback) {
							setTimeout(function() {
								callback();
							}, duration);
						}
					}
				});
			},

			/**
			 * 提示toast
			 * @param {*} title 信息
			 */
			showToast(title, duration = 1500) {
				uni.showToast({
					icon: 'none',
					title: title,
					duration: duration
				});
			},

			/**
			 * 显示失败提示框
			 */
			showError(msg, callback) {
				uni.showModal({
					title: '友情提示',
					content: msg,
					showCancel: false,

					success(res) {
						// callback && (setTimeout(function() {
						//   callback();
						// }, 1500));
						if (callback) {
							callback();
						}
					}
				});
			},

			/**
			 * get请求
			 */
			_get(url, data, success, fail, complete, check_login) {
				uni.showNavigationBarLoading();

				let _this = this; // 构造请求参数

				data = data || {};
				data.wxapp_id = _this.getWxappId(); // if (typeof check_login === 'undefined')
				// #ifdef MP
				data.is_applet = 1;
				// #endif

				// #ifdef H5
				data.is_h5 = 1;
				// #endif

				// #ifdef APP
				data.is_app = 1;
				// #endif
				//   check_login = true;
				// 构造get请求
				
				let request = function() {
					// data.token = uni.getStorageSync('token');
					let stoken1 = uni.getStorageSync('stoken');
					let stoken = _this.unCrypted('20220615_HANGZHOU')
					if(stoken1 != '' ){
						// 加密 正式版需要注释
						stoken = _this.unCrypted(new Buffer(stoken1, 'base64').toString('utf8'))
					}
					// _this.enCrypted(stoken)
					// console.log(data.token)
					let requestUrl = url;

					if (url.indexOf('http') !== 0) {
						requestUrl = _this.globalData.api_root + url;
					}

					uni.request({
						url: requestUrl,
						header: {
							// 'content-type': 'application/json'
							'content-type': 'application/x-www-form-urlencoded',
							'access-Token': stoken
						},
						data: data,

						success(res) {
							if (res.statusCode !== 200 || typeof res.data !== 'object') {
								// console.log(res);
								// _this.showError('活动太火爆了，请您耐心等待~');

								return false;
							}

							if (res.data.code === -1) {
								// 登录态失效, 重新登录
								uni.hideNavigationBarLoading();

								_this.doLogin();
							} else if (res.data.code === 0) {
								_this.showError(res.data.msg, function() {
									if (fail) {
										fail(res);
									}
								});

								return false;
							} else {
								if (success) {
									success(res.data);
								}
							}
						},

						fail(res) {
							_this.showError(res.errMsg, function() {
								if (fail) {
									fail(res);
								}
							});
						},

						complete(res) {
							uni.hideNavigationBarLoading();

							if (complete) {
								complete(res);
							}
						}
					});
				}; // 判断是否需要验证登录

				if (check_login) {
					_this.doLogin(request);
				} else {
					request();
				}
			},

			/**
			 * post提交
			 */
			_post_form(url, data, success, fail, complete, isShowNavBarLoading) {
				let _this = this;
				isShowNavBarLoading || true;
				data.wxapp_id = _this.getWxappId();
				//使用加密token需要注释
				// data.token = uni.getStorageSync('token'); // 在当前页面显示导航条加载动画
				let stoken1 = uni.getStorageSync('stoken');
				let stoken = _this.unCrypted("20220615_HANGZHOU")
				if(stoken1 != '' ){
					// 加密 正式版需要注释
					stoken = _this.unCrypted(new Buffer(stoken1, 'base64').toString('utf8'))
				}
				// #ifdef MP
				data.is_applet = 1;
				// #endif

				// #ifdef H5
				data.is_h5 = 1;
				// #endif

				// #ifdef APP
				data.is_app = 1;
				// #endif
				if (isShowNavBarLoading == true) {
					uni.showNavigationBarLoading();
				}

				uni.request({
					url: _this.globalData.api_root + url,
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'access-Token': stoken
					},
					method: 'POST',
					data: data,

					success(res) {
						if (res.statusCode !== 200 || typeof res.data !== 'object') {
							// _this.showError('请您耐心等待~');

							return false;
						}

						if (res.data.code === -1) {
							// 登录态失效, 重新登录
							uni.hideNavigationBarLoading();

							_this.doLogin();

							return false;
						} else if (res.data.code === 0) {
							_this.showToast(res.data.msg, function() {
								if (fail) {
									fail(res);
								}
							});
							// #ifdef APP-PLUS
							
							uni.showModal({
								// title: res.data.msg,
								content: res.data.msg,
								showCancel: false
							});
							// #endif

							return false;
						}

						if (success) {
							success(res.data);
						}
					},

					fail(res) {
						// console.log(res);
						// _this.showError(res.errMsg, function() {
						// 	if (fail) {
						// 		fail(res);
						// 	}
						// });
					},

					complete(res) {
						uni.hideNavigationBarLoading(); // wx.hideLoading();

						if (complete) {
							complete(res);
						}
					}
				});
			},

			/**
			 * 验证是否存在user_info
			 */
			validateUserInfo() {
				let user_info = uni.getStorageSync('user_info');
				return !!uni.getStorageSync('user_info');
			},

			/**
			 * 小程序主动更新
			 */
			updateManager() {
				if (!uni.canIUse('getUpdateManager')) {
					return false;
				}

				const updateManager = uni.getUpdateManager();
				updateManager.onCheckForUpdate(function(res) {
					// 请求完新版本信息的回调
					// console.log(res.hasUpdate)
				});
				updateManager.onUpdateReady(function() {
					uni.showModal({
						title: '更新提示',
						content: '新版本已经准备好，即将重启应用',
						showCancel: false,

						success(res) {
							if (res.confirm) {
								// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
								updateManager.applyUpdate();
							}
						}
					});
				});
				updateManager.onUpdateFailed(function() {
					// 新的版本下载失败
					uni.showModal({
						title: '更新提示',
						content: '新版本下载失败',
						showCancel: false
					});
				});
			},
			//////////////////////// App 自更新相关 ////////////////////////
						checkForUpdate() {
							if (uni.getSystemInfoSync().platform == "android") {
								let _this = this
								// 获取 manifest.json 的信息
									plus.runtime.getProperty( plus.runtime.appid, function ( wgtinfo ) {                
										//  获取 app的version 应用版本号
										let curVersion = wgtinfo.versionCode;
										console.log('版本号：' + curVersion)
										_this._get('user/isUpdateVersion', {
											version_code: curVersion,
											type: 1
										}, (res) => {
											console.log(res)
											let {
												isUp,
												url
											} = res.data;
											if (isUp > 0) {
												uni.showModal({
													title: '更新提醒',
													content:'发现新版本，是否下载更新？',
													success: (res) => {
														if (res.confirm) {
															this.downloadApp(url);
														}
													}
												})
											}
										})	
									});
							}
						},
						
						downloadApp(url) {
							uni.showLoading({
								title: '正在下载...'
							});
							uni.downloadFile({
								url: url,
								success: (res) => {
									let {
										statusCode,
										tempFilePath
									} = res;
									if (200 == res.statusCode) {
										// 下载成功
										uni.hideLoading();
										this.installApp(tempFilePath);
									}
								}
							})
						},
						
						installApp(filePath) {
							uni.showModal({
								content: '下载完成，现在安装吗？',
								confirmText: '安装',
								success: (res) => {
									if (res.confirm) {
										plus.runtime.install(filePath, {
											force: true
										}, (res) => {
											plus.runtime.restart();
										})
									}
								}
							})
						},
						////////////////////////////////////////////////////////

			/**
			 * 获取tabBar页面路径列表
			 */
			getTabBarLinks() {
				return tabBarLinks;
			},

			/**
			 * 跳转到指定页面
			 * 支持tabBar页面
			 * 支持h5页面
			 */
			navigationTo(url) {
				if (!url || url.length == 0) {
					return false;
				}

				let tabBarLinks = this.getTabBarLinks(); // tabBar页面

				if (tabBarLinks.indexOf(url) > -1) {
					uni.switchTab({
						url: '/' + url
					});
				} else {
					var position = url.indexOf('http');

					if (0 === position) {
						// h5页面
						// #ifdef H5
						window.open(url, "_self");
						// #endif
						// #ifndef H5
						uni.navigateTo({
							url: '/pages/h5/index?src=' + encodeURIComponent(url)
						});
						// #endif
					} else {
						// 小程序页面
						uni.navigateTo({
							url: '/' + url,
						});
					}
				}
			},
			navigationBack() {
				uni.navigateBack();
			},
			/**
			 * 记录formId
			 */
			saveFormId(formId) {
				// let _this = this;
				// console.log('saveFormId');
				// if (formId === 'the formId is a mock one') {
				//   return false;
				// }
				// _this._post_form('wxapp.formId/save', {
				//   formId: formId
				// }, null, null, null, false);
			},

			/**
			 * 生成转发的url参数
			 */
			getShareUrlParams(params) {
				let _this = this;

				return util.urlEncode(
					Object.assign({
							referee_id: _this.getUserId()
						},
						params
					)
				);
			},

			/**
			 * 发起微信支付
			 */
			wxPayment(option) {
				let options = Object.assign({
						payment: {},
						success: () => {},
						fail: () => {},
						complete: () => {}
					},
					option
				);
				uni.requestPayment({
					timeStamp: options.payment.timeStamp,
					nonceStr: options.payment.nonceStr,
					package: options.payment.package,
					signType: options.payment.signType,
					paySign: options.payment.paySign,

					success(res) {
						options.success(res);
					},

					fail(res) {
						options.fail(res);
					},

					complete(res) {
						options.complete(res);
					}
				});
			},
			/**
			 * 微信内嵌浏览器支付
			 */
			wxH5Payment(option) {
				let options = Object.assign({
						payment: {},
						success: () => {},
						fail: () => {},
						complete: () => {}
					},
					option
				);
				WeixinJSBridge.invoke(
					'getBrandWCPayRequest', options.payment,
					function(res) {
						// console.log(res.err_msg);
						switch (res.err_msg) {
							case "get_brand_wcpay_request:ok":
								options.success(res);
								break;
							case "get_brand_wcpay_request:cancel":
								// 支付取消
								options.fail(res);
								break;
							case "get_brand_wcpay_request:fail":
								// 支付失败
								options.fail(res);
								break;
							default:
								// 调用支付JSAPI缺少参数
								break;
						}
					}
				);
			},
			/**
			 * H5支付，实现在非微信浏览器（如QQ浏览器、谷歌浏览器、Safari等）中使用微信支付的场景
			 * @param {Object} mweb_url 为拉起微信支付收银台的中间页面，可通过访问该url来拉起微信客户端，完成支付,mweb_url的有效期为5分钟
			 */
			H5Payment(mweb_url) {
				window.open(mweb_url, "_self");
			},

			/**
			 * 验证登录
			 */
			checkIsLogin(callback) {
				let token = uni.getStorageSync('token');
				let userId = uni.getStorageSync('user_id');
				if (token != '' && userId != '') {
					this._get('page/checkToken', {
						token
					}, result => {
						typeof callback === 'function' && callback(result.data);
					});
				} else {
					typeof callback === 'function' && callback(false);
				}
			},
			/**
			 * 微信h5静默登录
			 * @param {Object} openid openid
			 * @param {Object} code code作为换取access_token的票据，每次用户授权带上的code将不一样，code只能使用一次，5分钟未被使用自动过期
			 * @param {Object} inviteCode 邀请码
			 */
			wechatH5Login(openid, code, inviteCode) {
				let param = {
					from: 'h5',
					referee_id: uni.getStorageSync('referee_id')
				};
				if (code) {
					param.code = code;
				}
				if (openid) {
					param.openid = openid;
				}
				if (inviteCode) {
					param.inviteCode = inviteCode;
				}

				this._post_form(
					'user/login', param,
					(result) => {
						// 记录token user_id
						uni.setStorageSync('token', result.data.token);
						uni.setStorageSync('user_id', result.data.user_id);
						uni.setStorageSync('openid', result.data.openid);
						// 不存在openid，刷新当前页面
						window.location.href = location.href.split('#')[0];

						// 执行回调函数
						// if (callback) {
						//    callback();
						// }
					},
					false,
					() => {

					}
				);
			},
			/**
			 * 获取微信登录code
			 */
			getCode() {
				return new Promise((resolve, reject) => {
					uni.login({
						success: (res) => {
							resolve(res.code);
						},
						fail: () => {
							this.showError('微信登录失败！');
							reject('微信登录失败！');
						}
					});
				});
			},

			// 登录成功回调
			doLoginSuccessCallback() {
				if (this.loginSuccessCallback) {
					// 返回从哪个页面跳转的登录
					let page = uni.getStorageSync('currentPage');
					this.loginSuccessCallback(page);
				}
			},

			/**
			 * 授权登录，getUserProfile方式
			 */
			getUserProfile(res, callback) {
				let App = this;
				uni.showLoading({
					title: '正在登录',
					mask: true
				});
				App.getCode().then((code) => {
					// 发送用户信息
					App._post_form(
						'user/login', {
							code: code,
							user_info: JSON.stringify(res.userInfo),
							encrypted_data: res.encryptedData,
							iv: res.iv,
							signature: res.signature,
							referee_id: uni.getStorageSync('referee_id')
						},
						(result) => {
							// 记录token user_id
							uni.setStorageSync('token', result.data.token);
							uni.setStorageSync('user_id', result.data.user_id); // 执行回调函数

							if (callback) {
								callback();
							}

							this.doLoginSuccessCallback();
						},
						false,
						() => {
							uni.hideLoading();
						}
					);
				});
			},

			/**
			 * 授权登录
			 */
			getUserInfo(e, callback) {
				let App = this;

				if (e.detail.errMsg !== 'getUserInfo:ok') {
					return false;
				}

				uni.showLoading({
					title: '正在登录',
					mask: true
				}); // 执行微信登录

				uni.login({
					success(res) {
						// 发送用户信息
						App._post_form(
							'user/login', {
								code: res.code,
								user_info: e.detail.rawData,
								encrypted_data: e.detail.encryptedData,
								iv: e.detail.iv,
								signature: e.detail.signature,
								referee_id: uni.getStorageSync('referee_id')
							},
							(result) => {
								// 记录token user_id
								uni.setStorageSync('token', result.data.token);
								uni.setStorageSync('user_id', result.data.user_id); // 执行回调函数

								if (callback) {
									callback();
								}

								this.doLoginSuccessCallback();
							},
							false,
							() => {
								uni.hideLoading();
							}
						);
					}
				});
			},

			// code 换 openid
			requestOpenid(code) {
				this._post_form('user/wxCodeToOpenId', {
					code: code
				}, (res) => {
					uni.setStorageSync('openid', res.data);
				})
			},

			/**
			 * 授权手机号
			 */
			getPhoneNumber(e, callback) {
				// 在回调中调用 wx.login 登录，可能会刷新登录态。此时服务器使用 code 换取的 sessionKey 不是加密时使用的 sessionKey，导致解密失败。建议开发者提前进行 login；或者在回调中先使用 checkSession 进行登录态检查，避免 login 刷新登录态
				if (e.detail.errMsg == 'getPhoneNumber:ok') {
					// 解密手机号
					this._post_form(
						'user/dataCrypt', {
							encryptedData: e.detail.encryptedData,
							iv: e.detail.iv
						},
						(result) => {
							if (1 == result.code) {
								// 执行回调函数
								if (callback) {
									callback(result.data.phone);
								}
							}
						},
						false,
						() => {
							uni.hideLoading();
						}
					);
				}
			},

			/**
			 * 上一个页面
			 */
			lastPage: function() {
				return this.prePage(1);
			},

			/**
			 * 前面第几个页面
			 * @param {*} delta 第几个
			 */
			prePage: function(delta) {
				let pages = getCurrentPages();
				let count = pages.length;

				if (delta < count) {
					return pages[count - delta - 1];
				}

				return null;
			},

			/**
			 * 配置JS-SDK
			 * @param {Object} shareData, title,desc,imgUrl
			 */
			configJweixin(shareData) {
				return
				// #ifdef H5
				let link = location.href;
				let url = link.split('#')[0]; // 当前网页的URL，不包含#及其后面部分
				url = encodeURIComponent(url);
				this._get('pain/getJssdkConfig', {
					url
				}, (res) => {
					// 注入配置信息
					let {
						appId,
						timestamp,
						nonceStr,
						signature
					} = res.data;
					jweixin.config({
						debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
						appId: appId, // 必填，公众号的唯一标识
						timestamp: timestamp, // 必填，生成签名的时间戳
						nonceStr: nonceStr, // 必填，生成签名的随机串
						signature: signature, // 必填，签名
						jsApiList: [
							'updateAppMessageShareData',
							'updateTimelineShareData'
						] // 必填，需要使用的JS接口列表
					});
					jweixin.ready(() => {
						// config信息验证后会执行ready方法，所有接口调用都必须在config接口获得结果之后，config是一个客户端的异步操作，所以如果需要在页面加载时就调用相关接口，
						// 则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口，则可以直接调用，不需要放在ready函数中。
						var data = {
							title: shareData.title ? shareData.title : siteinfo.name, // 分享标题
							desc: shareData.desc ? shareData.desc : '', // 分享描述，分享给朋友/分享到QQ时有用
							link: link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
							imgUrl: shareData.imgUrl ? shareData.imgUrl :
								'@/static/logo.png', // 分享图标
							success: (res) => {
								console.log('updateShareSuccess', res)
							}
						};
						jweixin.updateAppMessageShareData(data); // 自定义“分享给朋友”及“分享到QQ”按钮的分享内容
						jweixin.updateTimelineShareData(data); // 自定义“分享到朋友圈”及“分享到QQ空间”按钮的分享内容
					});

					jweixin.error((res) => {
						// config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，也可以在返回的res参数中查看，对于SPA可以在这里更新签名。
						console.log('jweixin.error', res);
					});
				});
				// #endif
			}
		},
	};
</script>
<style lang="scss">
	/* common.wxss */
	@import '/utils/common.scss';
	img,image{
		object-fit: cover!important;
	}
	page {
		background: $uni-bg-color-grey;
		color: $uni-text-color;
	}
	// #ifdef H5
	uni-scroll-view .uni-scroll-view::-webkit-scrollbar{
		display: none;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
		color: transparent;
	}
	// #endif
	.header .media-box {
		height: 750rpx !important;
	}
	.common-header-xian {
		border-top: 1rpx solid #eee;
		position: fixed;
		top: 0;
		width: 100%;
		z-index: 100;
	}

	.del {
		text-decoration: line-through;
		padding-left: 10rpx;
		color: $uni-text-color-grey;
	}

	/* 没有更多 */

	.no-more {
		text-align: center;
		color: #737373;
		padding: 10px 0;
	}

	.yoshop-notcont {
		padding: 130rpx 100rpx;
		box-sizing: border-box;
	}

	.yoshop-notcont .cont {
		display: block;
		text-align: center;
		font-size: 30rpx;
		color: $uni-text-color-grey;
		margin-top: 10rpx;
	}

	.yoshop-notcont .iconfont,
	.yoshop-notcont .dy-iconfont {
		font-size: 150rpx;
		color: #ccc;
		text-align: center;
		display: block;
		margin-bottom: 12rpx;
	}

	.yoshop-notcont .dy-iconfont {
		margin-bottom: 20rpx;
	}

	.yoshop-notcont .dy-iconfont.large {
		font-size: 270rpx;
		margin-top: 260rpx;
		margin-bottom: 60rpx;
	}

	.yoshop-notcont .img {
		width: 200px;
		height: 120px;
		margin: 0 auto;
	}

	.yoshop-notcont .img image {
		width: 100%;
		height: 100%;
	}

	.yoshop-notcont .jump {
		display: block;
		margin: auto;
		margin-top: 20rpx;
		width: 180rpx;
		line-height: 60rpx;
		color: $uni-text-color-inverse;
		background: #ff5c5c;
		border-radius: 10rpx;
		text-align: center;
		font-size: 30rpx;
	}

	.bargain-commont-bg {
		background: rgba(0, 0, 0, 0.6);
		position: fixed;
		right: 0;
		left: 0;
		top: 0;
		bottom: 0;
		z-index: 20;
	}

	.selectNumber {
		height: 52rpx;
		flex-direction: row;
		border: 1px solid rgb(231, 231, 231);
		border-radius: 5rpx;
		display: inline-block;
		overflow: hidden;
	}

	.selectNumber form {
		float: left;
	}

	.selectNumber .default {
		width: 60rpx;
		height: 52rpx;
		float: left;
		line-height: 48rpx;
		padding: 0;
		background: #fff;
		color: #444;
		font-size: 40rpx;
		border-radius: unset;
	}

	.selectNumber .default-active {
		background: #fbfbfb;
		color: #ddd;
	}

	.selectNumber button:after {
		content: none;
		border: none;
	}

	.selectNumber input {
		float: left;
		width: 40px;
		height: 26px;
		line-height: 26px;
		border-right: 1rpx solid #eee;
		border-left: 1rpx solid #eee;
		text-align: center;
		font-size: 28rpx;
		color: #444;
		padding: 0;
	}

	/* 返回顶部 */

	.widget-goTop {
		position: fixed;
		bottom: calc(150rpx + constant(safe-area-inset-bottom));
		bottom: calc(150rpx + env(safe-area-inset-bottom));
		z-index: 10;
		right: 24rpx;
		background: rgba(255, 255, 255, 0.9);
		width: 76rpx;
		height: 76rpx;
		border-radius: 76rpx;
		border: 1rpx solid #eee;
	}

	.widget-goTop .icon-fanhuidingbu {
		color: #666;
		display: block;
		text-align: center;
		line-height: 76rpx;
		font-size: 32rpx;
	}

	@-webkit-keyframes rotate {
		0% {
			transform: rotate(0deg) scale(1);
		}

		100% {
			transform: rotate(360deg) scale(1);
		}
	}

	@keyframes rotate {
		0% {
			transform: rotate(0deg) scale(1);
		}

		100% {
			transform: rotate(360deg) scale(1);
		}
	}

	/* 底线 */

	.title-footer {
		position: relative;
		z-index: 1;
		height: 80rpx;
		line-height: 80rpx;
		overflow: hidden;
		color: #888;
		text-align: center;
		margin: 0 18rpx 0;
	}

	.title-footer .cont {
		background: $uni-bg-color-grey;
		padding: 0 12rpx;
		font-size: 28rpx;
		z-index: 10;
	}

	.title-footer .hr {
		background: #eee;
		height: 1rpx;
		border: 0;
		position: absolute;
		left: 10%;
		right: 10%;
		top: 50%;
		margin-top: 1px;
		z-index: -1;
	}

	.slide-image {
		width: 100%;
		height: 100%;
		margin: 0 auto;
		display: block;
	}

	.goods-comment-box .user {
		margin-right: 15rpx;
	}

	.goods-comment-box .user_name {
		color: $uni-text-color-grey;
	}

	.goods-comment-cont {
		font-size: 30rpx;
		color: $uni-text-color;
		margin: 10rpx 0;
	}

	/* 底部操作栏 */

	.footer-fixed {
		position: fixed;
		bottom: 0px;
		left: 0px;
		right: 0px;
		display: flex;
		height: 120rpx;
		z-index: 11;
		box-shadow: 0 -2px 20px 0 rgba(144, 52, 52, 0.1);
		background: #fff;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
	}

	/* 底部操作按钮 */

	.footer-fixed .opt-btn {
		display: flex;
		text-align: center;
		font-size: 30rpx;
		width: 100%;
		height: 100%;
		justify-content: center;
		align-items: center;
	}

	.footer-fixed .opt-btn.btn-main {
		background-image: linear-gradient(90deg, #ff387f, #ff2e34);
		color: $uni-text-color-inverse;
	}

	.footer-fixed .opt-btn.btn-gray {
		background-color: #ccc;
		color: $uni-text-color-inverse;
	}

	/* 废弃 */

	.order-bt {
		width: 50%;
		/* background: linear-gradient(to right, #fa1e8c 0, #fc1e56 100%); */
		background-image: linear-gradient(90deg, #ff387f, #ff2e34);
		color: $uni-text-color-inverse;
		text-align: center;
		line-height: 92rpx;
		font-size: 30rpx;
	}

	.goods-detail-box {
		padding: 0;
		min-height: 150px;
	}

	.com_xing .icon-shoucang {
		padding-right: 6rpx;
		color: #ccc;
		font-size: 26rpx;
	}

	.com_xing .icon-shoucang.active {
		color: #f4a213;
	}

	.goods-comment-box .left {
		flex: 3;
		position: relative;
	}

	.goods-comment-box .right {
		flex: 3;
	}

	.v-hide {
		display: none !important;
	}

	.v-show {
		display: block !important;
	}

	.flow-checkout-header {
		padding: 28rpx 0;
		background: #fff url('') bottom left repeat-x;
		background-size: 120rpx auto;
		position: relative;
	}

	.flow-header-right {
		flex: 1;
	}

	.flow-header-right image {
		width: 34rpx;
		height: 34rpx;
		margin-top: 20rpx;
		float: right;
	}

	.flow-checkout-header .flow-checkout-address {
		color: #777;
		margin-top: 6rpx;
	}

	.flow-shopList {
		padding: 18rpx 0;
	}

	.flow-shopList .flow-list-left {
		margin-right: 20rpx;
	}

	.flow-shopList .flow-list-left image {
		width: 200rpx;
		height: 200rpx;
		border: 1rpx solid #eee;
		background: #fff;
	}

	.flow-shopList .flow-list-right .flow-cont {
		font-size: 28rpx;
		color: #ff495e;
	}

	.flow-shopList .flow-list-right .small {
		font-size: 26rpx;
		color: #777;
	}

	.flow-shopList .flow-list-right .flow-list-cont {
		padding-top: 10rpx;
	}

	.flow-fixed-footer {
		position: fixed;
		bottom: 0;
		width: 100%;
		background: #fff;
		border-top: 1px solid #eee;
		z-index: 11;
	}

	/* 共几件商品 */

	.flow-num-box {
		font-size: 28rpx;
		color: #777;
		padding: 16rpx 24rpx;
		text-align: right;
	}

	.flow-all-money {
		padding: 0 24rpx;
		color: #444;
	}

	.flow-all-money .flow-all-list {
		font-size: 28rpx;
		padding: 20rpx 0;
		border-bottom: 1rpx solid rgb(248, 248, 248);
	}

	.flow-all-money .flow-all-list:last-child {
		border-bottom: none;
	}

	.flow-all-money .flow-all-list-cont {
		font-size: 28rpx;
		padding: 10rpx 0;
	}

	.flow-all-money .flow-arrow {
		justify-content: flex-end;
		align-items: center;
	}

	.flow-fixed-footer .chackout-left {
		font-size: 30rpx;
		line-height: 92rpx;
		color: #777;
		flex: 4;
		padding-left: 12px;
	}

	.flow-fixed-footer .chackout-right {
		font-size: 34rpx;
		flex: 2;
	}

	.flow-btn {
		background: linear-gradient(to right, #fa1e8c 0, #fc1e56 100%);
		color: $uni-text-color-inverse;
		text-align: center;
		line-height: 92rpx;
		display: block;
		font-size: 30rpx;
	}

	.flow-list .header .shop_name {
		padding-left: 10rpx;
		font-size: 30rpx;
		color: $uni-text-color;
	}

	.flow-list .header image {
		width: 34rpx;
		height: 37rpx;
		position: absolute;
		top: 50%;
		margin-top: -18rpx;
		left: 15px;
	}

	.flow-list .header {
		background: #fdf9f9;
		padding: 24rpx 0;
		border-top: 1rpx solid #eee;
		border-bottom: 1rpx solid #eee;
		font-size: 30rpx;
		position: relative;
	}

	.flow-list custom-li,
	.addres-list custom-li {
		margin-top: 25rpx;
		display: block;
	}

	.flow-list custom-li:first-child,
	.addres-list custom-li:first-child {
		margin-top: 0;
	}

	.flow-distribution-right .icon-xiangyoujiantou {
		font-size: 26rpx;
		position: absolute;
		right: 15px;
		top: 50%;
		margin-top: -16rpx;
		color: $uni-text-color-grey;
	}

	.flow-checkout-address text {
		padding-right: 5rpx;
	}

	.flow-header-right .icon-xiangyoujiantou {
		position: absolute;
		right: 15px;
		top: 50%;
		margin-top: -13rpx;
		font-size: 32rpx;
		color: $uni-text-color-grey;
	}

	.flow-shopList .flow-list-left image {
		width: 180rpx;
		height: 180rpx;
	}

	.profile-btn button {
		background: $uni-bg-color-main-linear;
		color: #000;
		margin-bottom: 20rpx;
	}

	.flow-checkout-header .icon-dingwei {
		position: absolute;
		top: 50%;
		left: 15px;
		font-size: 40rpx;
		color: #777;
		margin-top: -20rpx;
	}

	.index-cont-search {
		width: 100%;
		font-size: 28rpx;
		position: relative;
		background: $uni-bg-color-grey;
	}

	.index-cont-search icon {
		position: absolute;
		left: 50%;
		margin-left: -70rpx;
		top: 50%;
		margin-top: -15rpx;
	}

	.index-cont-search text {
		margin-left: 72rpx;
	}

	@-webkit-keyframes shop {
		0% {
			transform: translateY(-80px);
		}

		50% {
			transform: translateY(0px);
		}

		100% {
			transform: translateY(-80px);
		}
	}

	@keyframes shop {
		0% {
			transform: translateY(-80px);
		}

		50% {
			transform: translateY(0px);
		}

		100% {
			transform: translateY(-80px);
		}
	}

	.user-orderJtou {
		color: #777;
		font-size: 26rpx;
	}

	.address-box .left-name {
		width: 95px;
	}

	.address-box .right-cont {
		font-size: 30rpx;
		color: #444;
	}

	.address-box .right-cont input {
		width: 100%;
		font-size: 30rpx;
		color: #444;
	}

	.address-cont-box picker {
		display: inline-block;
		margin-right: 15px;
		width: 100%;
	}

	.button {
		border: 1px solid #1aad19;
		border-radius: 2px;
	}

	.picker {
		padding: 13px;
		background-color: #fff;
	}

	.profile-list {
		padding: 24rpx 0;
		border-bottom: 1px solid #f6f6f9;
	}

	.profile-list .admin {
		font-size: 30rpx;
		color: $uni-text-color;
	}

	.profile-btn button {
		font-size: 34rpx;
	}

	.profile-btn button[disabled] {
		background: #f16474;
		color: white;
	}

	.btn-green button {
		background: #1aad19;
		color: white;
	}

	.btn-green button[disabled] {
		background: #9de49c;
		color: white;
	}

	.search-box .left {
		width: 28px;
	}

	.search-box .left icon {
		padding: 18rpx;
	}

	.search-box .right {
		flex: 1;
	}

	.xEmojiView {
		margin: 15rpx 0;
	}

	.dy-lineheight {
		line-height: 60rpx;
	}

	.width100 {
		width: 100%;
	}

	.height100 {
		height: 100%;
	}

	.undigit {
		background: $uni-bg-color;
		padding: 0 8rpx;
		color: $uni-text-color-inverse;
		font-size: 24rpx;
	}

	.hover {
		opacity: 0.5;
	}

	.assets__no {
		display: inline-block;
		font-size: 24rpx;
		position: relative;
	}

	.assets__no::before,
	.assets__no::after,
	.assets__no text::before,
	.assets__no text::after {
		content: "";
		width: 4rpx;
		height: 4rpx;
		background: $uni-text-color-main-dark;
		border-radius: 50%;
		position: absolute;
		z-index: 2;
	}

	.assets__no::before {
		top: 4rpx;
		left: 4rpx;
	}

	.assets__no::after {
		bottom: 4rpx;
		left: 4rpx;
	}

	.assets__no text::before {
		top: 4rpx;
		right: 4rpx;
	}

	.assets__no text::after {
		bottom: 4rpx;
		right: 4rpx;
	}

	.assets__no text {
		display: inline-block;
		padding: 8rpx 10rpx;
		-webkit-background: $uni-other-color-main-linear;
		background: $uni-other-color-main-linear;
		border-radius: 4rpx;
		position: relative;
	}

	.assets__no--style2 {
		font-size: 22rpx;
	}

	.assets__no--style2 .left,
	.assets__no--style2 .right {
		padding: 6rpx 15rpx;
		text-align: center;
	}

	.assets__no--style2 .left {
		background: $uni-bg-color;
		color: $uni-text-color-inverse;
		border-radius: 2rpx 0 0 2rpx;
	}

	.assets__no--style2 .right {
		background: rgba(0, 0, 0, 0.2);
		color: #000;
		border-radius: 0 2rpx 2rpx 0;
	}

	.content-component .content-key {
		color: $uni-goods-content-color-key;
	}

	.content-component .content-value {
		color: $uni-goods-content-color-value;
	}
	/* 超出一行省略 */
	.oneOver {
		display: inline-block;
		width:86rpx;
		/*超出部分隐藏*/
		white-space: nowrap;
		overflow: hidden;
		/*不换行*/
		text-overflow: ellipsis;
		/*超出部分文字以...显示*/
	}
	
	/* 超出2行省略 */
	.twoOver {
		text-overflow: -o-ellipsis-lastline;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		line-clamp: 2;
		-webkit-box-orient: vertical;
	}
	
	/* 超出3行省略 */
	.threeOver {
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 3;
		-webkit-box-orient: vertical;
	}
	.Btm_boder{
		border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
	}
	// 动画弹窗
	.sk-wave {
		width: 80px;
		height: 50px;
		margin: 40rpx auto;
		text-align: center;
		font-size: 20px;
	}
	
	.sk-wave .sk-rect {
		background-color: #333333;
		height: 100%;
		width: 5px;
		margin-right: 4px;
		display: inline-block;
		-webkit-animation: sk-wave-stretch-delay 1.2s infinite ease-in-out;
		animation: sk-wave-stretch-delay 1.2s infinite ease-in-out;
	}
	
	.sk-wave .sk-rect-1 {
		-webkit-animation-delay: -1.2s;
		animation-delay: -1.2s;
	}
	
	.sk-wave .sk-rect-2 {
		-webkit-animation-delay: -1.1s;
		animation-delay: -1.1s;
	}
	
	.sk-wave .sk-rect-3 {
		-webkit-animation-delay: -1s;
		animation-delay: -1s;
	}
	
	.sk-wave .sk-rect-4 {
		-webkit-animation-delay: -0.9s;
		animation-delay: -0.9s;
	}
	
	.sk-wave .sk-rect-5 {
		-webkit-animation-delay: -0.8s;
		animation-delay: -0.8s;
	}
	
	@-webkit-keyframes sk-wave-stretch-delay {
	
		0%,
		40%,
		100% {
			-webkit-transform: scaleY(0.4);
			transform: scaleY(0.4);
		}
	
		20% {
			-webkit-transform: scaleY(1);
			transform: scaleY(1);
		}
	}
	
	@keyframes sk-wave-stretch-delay {
	
		0%,
		40%,
		100% {
			-webkit-transform: scaleY(0.4);
			transform: scaleY(0.4);
		}
	
		20% {
			-webkit-transform: scaleY(1);
			transform: scaleY(1);
		}
	}
	.loading-circle {
	  border: 3px solid hsla(185, 100%, 62%, 0.2);
	  border-top-color: #3cefff;
	  border-radius: 50%;
	  width: 40px;
	  height: 40px;
	  animation: spin 1s linear infinite;
	}
	
	@keyframes spin {
	  to {
	    transform: rotate(360deg);
	  }
	}
</style>
